//
//  TextVC.swift
//  easyVideo-swift
//
//  Created by 李淼淼 on 2021/8/11.
//

import UIKit

class TextVC: UIViewController {
    var firstButton:UIButton! = nil
    var secondButton:UIButton! = nil
    var thirdButton:UIButton! = nil
    
    override func viewDidLoad() {
        super.viewDidLoad()

        createAButton()
        secondButton = createCustomButton(rect: CGRect(x: 200, y: 300, width: 100, height: 100), selector: #selector(buttonAction(_:)), color: .brown, titleText: "第二个按钮")
        self.view .addSubview(secondButton)
        thirdButton = createCustomButton(rect: CGRect(x: 300, y: 400, width: 100, height: 100), selector: #selector(buttonAction(_:)), color: .gray, titleText: "第三个按钮")
        self.view .addSubview(thirdButton)
    }


    func createAButton(){
        firstButton = UIButton.init(type: .custom)
        firstButton.frame = CGRect(x: 100, y: 100, width: 100, height: 100)
        firstButton.setTitle("第一个按钮", for: .normal)
        firstButton.addTarget(self, action: #selector(buttonAction(_:)), for: .touchUpInside)
        firstButton.backgroundColor = .red
        firstButton.setTitleColor(.white, for: .normal)
        self.view .addSubview(firstButton)
    }
    
    func createCustomButton(rect:CGRect, selector:Selector, color:UIColor, titleText:String)  ->UIButton
    {
        let button = UIButton.init(type: .custom)
        button.frame = rect
        button.setTitle(titleText, for: .normal)
        button.addTarget(self, action: selector, for: .touchUpInside)
        button.backgroundColor = color
        button.setTitleColor(.white, for: .normal)
        return button
    }
    
    @objc func buttonAction(_ button:UIButton){
        switch button {
        case firstButton:
            print("点击了第一个按钮")
            break
        case secondButton:
            print("点击了第二个按钮")
            firstButton.frame = CGRect(x: 100, y: 100, width: 50, height: 50)
            break
        case thirdButton:
            print("点击了三个按钮")
            firstButton.frame = CGRect(x: 100, y: 100, width: 100, height: 100)
            break
        
        default:
            break
        }
        
    }
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
